$(function () {
    getUserInfo()
    //退出按钮绑定事件
    $('#getout').on('click', function () {
        //eg1
        layer.confirm('是否退出?', { icon: 3, title: '提示' }, function (index) {
            //退出逻辑
            localStorage.removeItem('token');
            location.href = '/login.html';
            layer.close(index);
        });
    })
})
//获取信息
function getUserInfo() {
    $.ajax({
        type: 'GET',
        url: '/my/userinfo',
        headers: {
            Authorization: localStorage.getItem('token') || ''
        },
        success(res) {
            if (res.status !== 0) {
                return layer.msg(res.message || '获取信息失败')
            }
            renderAvatar(res.data)
        }
    })
}
2
// 渲染头像
function renderAvatar(user) {
    var name = user.nickname || user.username;
    $('#welcome').html(`欢迎&nbsp;&nbsp;${name}`);
    if (user.user_pic !== null) {
        $('.layui-nav-img')
            .attr('src', user.user_pic)
            .show()
        $('.text-avatar').hide()
    }
    else {
        // 3.2 渲染文本头像
        $('.layui-nav-img').hide()
        var first = name[0].toUpperCase()
        $('.text-avatar')
            .html(first)
            .show()
    }
}
